package com.tianji.learning.mapper;

import com.tianji.learning.domain.po.PointsRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;

/**
 * <p>
 * 学习积分记录，每个月底清零 Mapper 接口
 * </p>
 *
 * @author friday
 * @since 2024-01-11
 */
public interface PointsRecordMapper extends BaseMapper<PointsRecord> {

    /**
     * 查询用户在本周获得的积分
     */
    @Select("SELECT SUM(points) FROM points_record \n" +
            "WHERE user_id = #{userId} AND create_time >= #{weekBeginTime} AND create_time < #{weekEndTime}")
    Integer queryPointsByUserId(Long userId, LocalDateTime weekBeginTime, LocalDateTime weekEndTime);
}
